import { IChatMessage } from '../../interface';

/**
 * 消息实体
 *
 * @author chitanda
 * @date 2023-10-09 16:10:45
 * @export
 * @class ChatMessage
 * @implements {IMessage}
 */
export class ChatMessage implements IChatMessage {
  get messageid(): IChatMessage['messageid'] {
    return this.msg.messageid;
  }

  get state(): IChatMessage['state'] {
    return this.msg.state;
  }

  get role(): IChatMessage['role'] {
    return this.msg.role;
  }

  get type(): IChatMessage['type'] {
    return this.msg.type;
  }

  get content(): IChatMessage['content'] {
    return this.msg.content;
  }

  get _origin(): IChatMessage {
    return this.msg;
  }

  constructor(protected msg: IChatMessage) {}

  /**
   * 更新消息
   *
   * @author chitanda
   * @date 2023-10-10 17:10:07
   * @param {IChatMessage} msg
   */
  update(msg: IChatMessage): void {
    if (!msg.content) {
      msg.content = '';
    }
    this.msg.content += msg.content;
  }
}
